home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
OLE2BOOK.ZIP
/
CHAP13.ZIP
/
PATRON
/
PAGE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-27
|
32KB
|
1,315 lines
/*
* PAGE.CPP
* Modifications for Chapter 13
*
* Implementation of parts of the CPage class; those member functions
* dealing with mouse events are in PAGEMOUS.CPP
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include "patron.h"
/*
* CPage::CPage
* CPage::~CPage
*
* Constructor Parameters:
* dwID DWORD identifier for this page.
* hWnd HWND of the pages window (for repaints, etc).
* pPG LPCPages to the Pages window.
*/
CPage::CPage(DWORD dwID, HWND hWnd, LPCPages pPG)
{
m_dwID =dwID;
m_pIStorage=NULL;
m_cOpens=0;
m_hWnd=hWnd;
m_pPG=pPG;
m_dwIDNext =0;
m_cTenants =0;
m_hWndTenantList=NULL;
m_iTenantCur =0xFFFF; //Tenants are zero indexed.
m_pTenantCur =NULL;
m_uHTCode=HTNOWHERE;
m_uSizingFlags=0;
m_fTracking=FALSE;
m_hDC=NULL;
//CHAPTER13MOD
m_pmkFile=NULL;
m_cRef=0L;
m_pIOleItemContainer=NULL;
//End CHAPTER13MOD
return;
}
CPage::~CPage(void)
{
m_hWnd=NULL;
Close(FALSE);
return;
}
//CHAPTER13MOD
/*
* CPage::QueryInterface
* CPage::AddRef
* CPage::Release
*
* Purpose:
* IUnknown members for CPage object.
*/
STDMETHODIMP CPage::QueryInterface(REFIID riid, LPVOID FAR *ppv)
{
*ppv=NULL;
//Any interface on this object is the object pointer.
if (IsEqualIID(riid, IID_IUnknown))
*ppv=(LPVOID)this;
if (IsEqualIID(riid, IID_IOleItemContainer)
|| IsEqualIID(riid, IID_IOleContainer)
|| IsEqualIID(riid, IID_IParseDisplayName))
*ppv=(LPVOID)m_pIOleItemContainer;
if (NULL!=*ppv)
{
((LPUNKNOWN)*ppv)->AddRef();
return NOERROR;
}
return ResultFromScode(E_NOINTERFACE);
}
STDMETHODIMP_(ULONG) CPage::AddRef(void)
{
return ++m_cRef;
}
STDMETHODIMP_(ULONG) CPage::Release(void)
{
ULONG cRefT;
cRefT=--m_cRef;
if (0L==m_cRef)
delete this;
return cRefT;
}
//End CHAPTER13MOD
/*
* CPage::GetID
*
* Return Value:
* DWORD dwID field in this page. This function is only here
* to avoid hiding inline implementations in pages.h
*/
DWORD CPage::GetID(void)
{
return m_dwID;
}
/*
* CPage::FOpen
*
* Purpose:
* Retrieves the IStorage associated with this page. The IStorage is
* owned by the page and thus the page always holds a reference count.
* The caller should call ::Close or delete this page to match this open.
*
* This function may be called multiple times resulting in additional
* reference counts on the storage each of which must be matched with
* a call to ::Close. The last ::Close can be done through delete.
*
* Parameters:
* pIStorage LPSTORAGE in which this page lives.
*
* Return Value:
* BOOL TRUE if opening succeeds, FALSE otherwise.
*/
BOOL CPage::FOpen(LPSTORAGE pIStorage)
{
HRESULT hr=NOERROR;
LPSTREAM pIStream;
DWORD dwMode;
char szTemp[32];
BOOL fNew;
BOOL fCreated=FALSE;
TENANTLIST tl;
LPTENANTINFO pti;
ULONG cb;
LPMALLOC pIMalloc;
UINT i;
LPTENANT pTenant;
UINT cLinks;
LPOLELINK pIOleLink;
LPUNKNOWN pIUnknown;
UINT uRet;
OLEUIEDITLINKS el;
LPCIOleUILinkContainer pIUILinks;
HWND hWndDoc;
fNew=(NULL==m_pIStorage);
if (!fNew)
{
m_cOpens++;
m_pIStorage->AddRef();
return TRUE;
}
if (NULL==pIStorage)
return FALSE;
/*
* Attempt to open the storage under this ID. If there is none, then
* create it. In either case we end up with an IStorage that we
* either save in pPage or release.
*/
GetStorageName(szTemp);
dwMode=STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
hr=pIStorage->OpenStorage(szTemp, NULL, dwMode, NULL, 0, &m_pIStorage);
if (FAILED(hr))
{
hr=pIStorage->CreateStorage(szTemp, dwMode, 0, 0, &m_pIStorage);
fCreated=TRUE;
}
if (FAILED(hr))
return FALSE;
m_cOpens++;
if (NULL==m_hWndTenantList)
{
/*
* The first time we open this page, create the hidden listbox
* we'll use to track tenants. We give it the owner-draw style
* so we can just store pointers in it.
*/
m_hWndTenantList=CreateWindow("listbox", "Tenant List"
, WS_POPUP | LBS_OWNERDRAWFIXED, 0, 0, 100, 100
, HWND_DESKTOP, NULL, m_pPG->m_hInst, NULL);
if (NULL==m_hWndTenantList)
return FALSE;
}
//CHAPTER13MOD
m_pIOleItemContainer=new CImpIOleItemContainer((LPVOID)this
, (LPUNKNOWN)this, FALSE);
if (NULL==m_pIOleItemContainer)
return FALSE;
//End CHAPTER13MOD
//If this is brand-new, we're done.
if (fCreated)
return TRUE;
/*
* Now open the stream we saved in ::Close and load all the
* tenants listed in there. If there are none, then we don't
* have to load squat.
*/
hr=m_pIStorage->OpenStream(SZSTREAMTENANTLIST, NULL, STGM_DIRECT
| STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pIStream);
if (FAILED(hr))
return FALSE;
if (SUCCEEDED(CoGetMalloc(MEMCTX_SHARED, &pIMalloc)))
{
pIStream->Read((LPVOID)&tl, sizeof(tl), NULL);
m_cTenants=tl.cTenants;
m_dwIDNext=tl.dwIDNext;
m_iTenantCur=0;
cb=tl.cTenants*sizeof(TENANTINFO);
if (0!=cb)
{
pti=(LPTENANTINFO)pIMalloc->Alloc(cb);
if (NULL!=pti)
{
pIStream->Read((LPVOID)pti, cb, NULL);
for (i=0; i < m_cTenants; i++)
{
if (FTenantAdd(-1, (pti+i)->dwID, &pTenant))
{
pTenant->FLoad(m_pIStorage, &(pti+i)->fe, &(pti+i)->rcl);
pTenant->ShowObjectType(m_pPG->m_fShowTypes);
}
}
pIMalloc->Free((LPVOID)pti);
}
}
pIMalloc->Release();
}
pIStream->Release();
//Get and select the first tenant
if (FTenantGet(0, &m_pTenantCur, FALSE))
m_pTenantCur->Select(TRUE);
/*
* Update all the links in this page, showing the progress indicator
* as it's happening. We use the same IOlUILinkContainer
* implementation as we do for the links dialog, passing it to
* OleUIUpdateLinks which does everything for us.
*
* We might also optimize this to not do anything if there are no
* automatic links, but it's not a big concern.
*/
//First, count the number of automatic links.
cLinks=0;
for (i=0; i < m_cTenants; i++)
{
if (FTenantGet(i, &pTenant, FALSE))
{
DWORD dw;
pTenant->ObjectGet(&pIUnknown);
hr=pIUnknown->QueryInterface(IID_IOleLink, (LPLPVOID)&pIOleLink);
pIUnknown->Release();
if (FAILED(hr))
continue;
pIOleLink->GetUpdateOptions(&dw);
pIOleLink->Release();
if (OLEUPDATE_ALWAYS==dw)
cLinks++;
}
}
//If we have any automatic links, invoke the update